package DirectoryViewer;

import java.io.File;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * User: Андрей
 * Date: 10.12.13
 * Time: 20:27
 * To change this template use File | Settings | File Templates.
 */
public class tree     implements ICommandExecutor
{
    public void execute(String path)
    {
        File f = new File(path);
        printDir(f,1);
    }

    public static void printDir(File dir, int hierarchyNum) {

        for (int i = 0; i < hierarchyNum; i++)
            System.out.print(' ');
        if(dir.isFile())
            System.out.println(dir.getName());
        if(dir.isDirectory())
            System.out.println("[+]"+dir.getName());
        if (dir.isDirectory()) {
            File[] files = dir.listFiles();
            for (int i = 0; i < files.length; i++)
                printDir(files[i],hierarchyNum + 2);
        }

    }
}
